import util from '../../common/js/util'
import NProgress from 'nprogress'
import axios from 'axios';

import moment from 'moment'

import routes from '../../routes'
import dMember from '../../../models/dict/dMember';
export default {
    data() {
        return {
            filters: {
                name: ''
            },
            memberList: [],
            total: 0,
            page: 1,
            listLoading: false,
            sels: [],//列表选中列

            editFormVisible: false,//编辑界面是否显示
            editLoading: false,
            editFormRules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' }
                ]
            },
            //编辑界面数据1
            editForm: {
                id: 0,
                name: '',
                sex: -1,
                age: 0,
                birth: '',
                addr: ''
            },

            addFormVisible: false,//新增界面是否显示
            addLoading: false,
            ShowSave: false,
            addFormRules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' }
                ]
            },
            //新增界面数据
            addForm: {
                name: '',
                sex: -1,
                age: 0,
                birth: '',
                addr: ''
            },
            currObj: {
                address: {}
            },
    
            selectedOptions: ["330000", "330100", "330110"],

            v: [],
            defaultProps: {
                children: 'children',
                label: 'name'
            },
            data2: routes.menus()


        }
    },
    methods: {

        append(store, data) {
            //      store.append({ id: id++, label: 'testtest', children: [] }, data);
        },

        remove(store, data) {
            store.remove(data);
        },

        renderContent(h, { node, data, store }) {


            /*
                        return (
                            <span>
                                <span>
                                    <span>{node.label}</span>
                                </span>
                                <span style="float: right; margin-right: 20px">
                                    <el-button size="mini" on-click={() => this.append(store, data)}>Append</el-button>
                                    <el-button size="mini" on-click={() => this.remove(store, data)}>Delete</el-button>
                                </span>
                            </span>)*/
        },

        //性别显示转换
        formatSex: function (row, column) {
            return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
        },
        fmtDate: function (row, col) {

            return moment(row.createTime).format("YYYY-MM-DD HH:mm:ss");

        },
       
    

        handleCurrentChange(val) {
            this.page = val;
            this.getMemberList();
        },
        //获取用户列表
        getRoleList() {

            this.listLoading = true;
            NProgress.start();
            axios.post("/a", {
                class: "member",
                para: "getRoleList",
                j: {
                    data: {



                        companyCode: localStorage.companyCode


                    },
                    page: this.page


                }

            }).then((res) => {

                this.memberList = res.data.list;

                this.total = res.data.total;
                this.listLoading = false;
                NProgress.done();


            });
        },
        addMember() {

            this.currObj = {

                address: {},
                class: []
            }
            this.ShowSave = true;
        },

        //删除
        handleDel: function (index, row) {

        },
        //显示编辑界面
        toSaveRole: function (index, row) {

            var _this = this;
            axios.post("/a", {
                class: "member",
                para: "getRole",
                j: {
                    _id: this.memberList[index]._id
                }

            }).then((res) => {

                if (!res.data.info.class) {
                    res.data.info.class = [];


                }

                this.currObj = dMember.fmtRole(res.data.info);



                this.ShowSave = true;


                setTimeout(function () {
                    _this.$refs.menuTree.setCheckedKeys(_this.currObj.menuIdArray);
                }, 500);



              
            });

        },
        //保存客户
        saveRole: function () {


            this.currObj.companyCode = localStorage.companyCode;
            this.currObj.menuIdArray = this.$refs.menuTree.getCheckedKeys();
            axios.post("/a", {
                class: "member",
                para: "saveRole",
                j: this.currObj

            }).then((res) => {
                if (res.data.re == "ok") {
                    this.ShowSave = false;
                    this.getRoleList();
                } else {
                    alert(JSON.stringify(res.data));
                }
            });


        },
        getPowerList() {
            return dMember.powerArray();
        }
        //新增





    },


    mounted() {
        this.getRoleList();
    },

}